<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;
class IndexController extends Controller{
	
	public function index(){
//		p($_SESSION);exit;
		if(!$_SESSION['id']){
			go(U('Login/index'));
		}
		View::make();
	}
	public function welcome(){
		View::make();
	}
	public function changePassword(){

		if(IS_POST){
			$oldPassword=Q('post.oldPassword','','md5');
			$newPassword=Q('post.newPassword','','md5');
			$confirmPassword=Q('post.confirmPassword','','md5');
			$uid=$_SESSION['id'];
			$data=Db::table('admin_user')->where("id={$uid}")->pluck('password');


			if($oldPassword!=$data){
				View::error('原密码错误');
			}
			if($newPassword!=$confirmPassword) View::error('两次输入密码不一致');
			Db::table('admin_user')->where("id={$uid}")->update(['password'=>$newPassword]);
			View::success('密码修改成功','ALogin/index');
			session_destroy();
			session_unset();

			
			echo '<script>parent.location.href="'.U('Login/index').'"</script>';
			exit;
		}
		View::make();
	}

}
